<%-- 
    Document   : index
    Created on : Jun 20, 2013, 9:28:00 PM
    Author     : Gustavo
--%>

<%@page import="yd2.edushare.Historial"%>
<%@page import="sun.awt.NullComponentPeer"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="javax.swing.table.DefaultTableModel"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>EduShare - Login</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">

        <!-- The styles -->
        <link id="bs-css" href="css/bootstrap-cerulean.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
        <link href="css/charisma-app.css" rel="stylesheet">
        <link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
        <link href='css/fullcalendar.css' rel='stylesheet'>
        <link href='css/fullcalendar.print.css' rel='stylesheet'  media='print'>
        <link href='css/chosen.css' rel='stylesheet'>
        <link href='css/uniform.default.css' rel='stylesheet'>
        <link href='css/colorbox.css' rel='stylesheet'>
        <link href='css/jquery.cleditor.css' rel='stylesheet'>
        <link href='css/jquery.noty.css' rel='stylesheet'>
        <link href='css/noty_theme_default.css' rel='stylesheet'>
        <link href='css/elfinder.min.css' rel='stylesheet'>
        <link href='css/elfinder.theme.css' rel='stylesheet'>
        <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
        <link href='css/opa-icons.css' rel='stylesheet'>
        <link href='css/uploadify.css' rel='stylesheet'>

        <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <!-- The fav icon -->
        <link rel="shortcut icon" href="img/favicon.ico">

    </head>

    <body>
        <div class="container-fluid">
            <div class="row-fluid">

                <div class="row-fluid">
                    <div class="span12 center login-header">
                        <h2>Bienvenido a EduShare</h2>
                    </div><!--/span-->
                </div><!--/row-->
                <div>
                    <center>
                        <img alt="Charisma Logo" src="img/logo_0001_EduShare.jpg" height="100px"/>
                    </center>
                </div>
                <div class="row-fluid">
                    <div class="well span5 center login-box">
                        <div class="alert alert-info">
                            Por favor inicia sesión con tu usuario y contraseña.
                        </div>
                        <form class="form-horizontal" method="post">
                            <fieldset>
                                <div class="input-prepend" title="Email" data-rel="tooltip">
                                    <input type="text" name="usuario" value="" />
                                    <span class="add-on"><i class="icon-user"></i></span></div>
                                <div class="clearfix"></div>

                                <div class="input-prepend" title="Password" data-rel="tooltip">
                                    <input type="password" name="pass" value="" />
                                    <span class="add-on"><i class="icon-lock"></i></span>
                                </div>
                                <div class="clearfix"></div>
                                <div class="clearfix"></div>
                                <p class="center span5">

                                    <input type="submit" class="btn btn-primary" value="Login" name="Login" />

                                </p>

                                <%

                                    if (request.getParameter("Login") != null) {
                                        String ruta = "jdbc:mysql://sql3.freemysqlhosting.net:3306/sql312735";
                                        String user = "sql312735";
                                        String clave = "sH9!yN8%";
                                        Connection conexion = null;
                                        Statement Sentencias = null;
                                        ResultSet tabla = null;
                                        try {
                                            Class.forName("com.mysql.jdbc.Driver").newInstance();
                                            conexion = DriverManager.getConnection(ruta, user, clave);
                                            Sentencias = conexion.createStatement();
                                        } catch (Exception e) {
                                            out.println("<script>alert('Error de Conexion')</script>");
                                        }


                                        //SE PIDEN LOS PARAMETROS DEL URL
                                        String usuario = request.getParameter("usuario");
                                        String passs = request.getParameter("pass");

                                        int b = 0;
                                        String us = null;
                                        String pa = null;
                                        String tipo = null;
                                        String id_usuario = null;

                                        out.print(usuario);
                                        out.print(passs);
                                        //la consulta SQL
                                        try {

                                            tabla = Sentencias.executeQuery("select "
                                                    + "id_usuario,"
                                                    + " email, "
                                                    + "password, "
                                                    + "tipo "
                                                    + "from USUARIO where email='" + usuario + "' ");



                                            while (tabla.next()) {
                                                id_usuario = tabla.getString("id_usuario");
                                                us = tabla.getString("email");
                                                pa = tabla.getString("password");
                                                tipo = tabla.getString("tipo");
                                                out.print(us);
                                                out.print(pa);
                                                if (us.equals(usuario) && pa.equals(passs)) {
                                                    b = 1;
                                                    //en esta linea agrego la variable de session correo
                                                    session.setAttribute("correo", us);
                                                    //en esta linea agrego la variable de session tipo
                                                    session.setAttribute("tipoUsuario", tipo);

                                                    //en esta linea agrego la variable de session tipo
                                                    session.setAttribute("id_usuario", id_usuario);
                                                    Historial.guardarEntrada(10, "El usuario "+us+" inicio sesion.", Integer.parseInt(id_usuario));
                                                    response.sendRedirect("index.jsp");
                                                } else {
                                                    out.println("<script>alert('Datos Erroneos  ')</script>");
                                                }

                                            }
                                            //luego comparamos si es uno es usuario existente y bien validado sino error


                                        } catch (Exception e) {
                                            out.println("<script>alert('Error')</script>");
                                            e.printStackTrace();
                                        }



                                    }

                                %>

                            </fieldset>
                        </form>
                        <div class="alert alert-info">
                            <a href="#" id="registrarse">Regístrate aquí</a> si no tienes una cuenta.
                        </div>
                    </div><!--/span-->
                </div><!--/row-->
            </div><!--/fluid-row-->

        </div><!--/.fluid-container-->

        <div class="modal hide fade" id="myModal">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">X</button>
                <h3>Regístrate!</h3>
            </div>
            <div class="modal-body">
                <fieldset>
                    <center>
                        <label class="control-label" for="txtNombre">nombre:</label>
                        <div class="input-prepend" title="Nombre" data-rel="tooltip">
                            <input type="text" id="txtNombre" name="User" value="" />
                            <span class="add-on"><i class="icon-user"></i></span></div>

                        <label class="control-label" for="txtEmail">email:</label>
                        <div class="input-prepend" title="Email" data-rel="tooltip">
                            <input type="text" id="txtEmail" name="Email" value="" />
                            <span class="add-on"><i class="icon-envelope"></i></span></div>
                        <div class="clearfix"></div>

                        <label class="control-label" for="txtNombre">Contraseña:</label>
                        <div class="input-prepend" title="Contraseña" data-rel="tooltip">
                            <input id="txtPass" type="password" name="pass" value="" />
                            <span class="add-on"><i class="icon-lock"></i></span>
                        </div>
                        <div class="clearfix"></div>
                        <label class="control-label" for="txtNombre">Confirmar Contraseña:</label>
                        <div class="input-prepend" title="Confirmar Contraseña" data-rel="tooltip">
                            <input id="txtPassConfirm" type="password" name="confpass" value="" />
                            <span class="add-on"><i class="icon-lock"></i></span>
                        </div>
                    </center>
                </fieldset>
            </div>
            <div class="modal-footer">
                <div id="ajaxLoader" >
                    <center>
                        <img src="img/ajax-loaders/ajax-loader-7.gif" title="img/ajax-loaders/ajax-loader-7.gif">
                    </center>
                </div>
                <div id="botonesRegistro">
                    <a href="#" class="btn" data-dismiss="modal">Cancelar</a>
                    <a href="#" id="btnRegistrarse" class="btn btn-primary">Registrarse</a>
                </div>
            </div>
        </div>


        <!-- external javascript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->

        <!-- jQuery -->
        <script src="js/jquery-1.7.2.min.js"></script>
        <!-- jQuery UI -->
        <script src="js/jquery-ui-1.8.21.custom.min.js"></script>
        <!-- transition / effect library -->
        <script src="js/bootstrap-transition.js"></script>
        <!-- alert enhancer library -->
        <script src="js/bootstrap-alert.js"></script>
        <!-- modal / dialog library -->
        <script src="js/bootstrap-modal.js"></script>
        <!-- custom dropdown library -->
        <script src="js/bootstrap-dropdown.js"></script>
        <!-- scrolspy library -->
        <script src="js/bootstrap-scrollspy.js"></script>
        <!-- library for creating tabs -->
        <script src="js/bootstrap-tab.js"></script>
        <!-- library for advanced tooltip -->
        <script src="js/bootstrap-tooltip.js"></script>
        <!-- popover effect library -->
        <script src="js/bootstrap-popover.js"></script>
        <!-- button enhancer library -->
        <script src="js/bootstrap-button.js"></script>
        <!-- accordion library (optional, not used in demo) -->
        <script src="js/bootstrap-collapse.js"></script>
        <!-- carousel slideshow library (optional, not used in demo) -->
        <script src="js/bootstrap-carousel.js"></script>
        <!-- autocomplete library -->
        <script src="js/bootstrap-typeahead.js"></script>
        <!-- tour library -->
        <script src="js/bootstrap-tour.js"></script>
        <!-- library for cookie management -->
        <script src="js/jquery.cookie.js"></script>
        <!-- calander plugin -->
        <script src='js/fullcalendar.min.js'></script>
        <!-- data table plugin -->
        <script src='js/jquery.dataTables.min.js'></script>

        <!-- chart libraries start -->
        <script src="js/excanvas.js"></script>
        <script src="js/jquery.flot.min.js"></script>
        <script src="js/jquery.flot.pie.min.js"></script>
        <script src="js/jquery.flot.stack.js"></script>
        <script src="js/jquery.flot.resize.min.js"></script>
        <!-- chart libraries end -->

        <!-- select or dropdown enhancer -->
        <script src="js/jquery.chosen.min.js"></script>
        <!-- checkbox, radio, and file input styler -->
        <script src="js/jquery.uniform.min.js"></script>
        <!-- plugin for gallery image view -->
        <script src="js/jquery.colorbox.min.js"></script>
        <!-- rich text editor library -->
        <script src="js/jquery.cleditor.min.js"></script>
        <!-- notification plugin -->
        <script src="js/jquery.noty.js"></script>
        <!-- file manager library -->
        <script src="js/jquery.elfinder.min.js"></script>
        <!-- star rating plugin -->
        <script src="js/jquery.raty.min.js"></script>
        <!-- for iOS style toggle switch -->
        <script src="js/jquery.iphone.toggle.js"></script>
        <!-- autogrowing textarea plugin -->
        <script src="js/jquery.autogrow-textarea.js"></script>
        <!-- multiple file upload plugin -->
        <script src="js/jquery.uploadify-3.1.min.js"></script>
        <!-- history.js for cross-browser state change on ajax -->
        <script src="js/jquery.history.js"></script>
        <!-- application script for Charisma demo -->
        <script src="js/charisma.js"></script>
        <script src="js/Registro.js"></script>
    </body>
</html>

